<?php
/*
 * litchicms
 * Copyright (C) 2010-5-25 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

!defined('BRK') && exit("!");
check_rights_by_id(18);
$can_action=array('show','update');

if(empty($_POST['action']) || !in_array($_POST['action'], $can_action)) {
    $_POST['action']='show';
}

switch ($_POST['action']) {
    case 'show':
        //查出所有用户
//        $BRK_CHA=brk_get_channel();
//        require 'tree.class.php';
//        $tree=new Tree($BRK_CHA,'ename','pename','cname');
//
//        $TREE=$tree->getChilds("0");
////        dump($tree);
////        dump($TREE);
//        array_shift($TREE);
////        dump($TREE);
//        $TREE=array_flip($TREE);
////        dump($TREE);
//        foreach ($TREE as $k=>&$channel) {
//            $channel=array($k,$tree->getValue($k),$tree->getLayer($k,"<span class='separator'>&nbsp;&nbsp;&nbsp;&nbsp;",1));
//        }
////        dump($TREE);
//        unset ($channel,$tree);

        break;
    case 'update':
    //修改默认首页
        if(array_key_exists('thisisindex',$_POST)) {
            brk_bglog("修改默认首页为".$_POST['thisisindex']);
            if(brk_update(
            "settings",
            array("set_value"=>$_POST['thisisindex']),
            "WHERE set_key='defualt_channel'")) {
                $BRK_MSG[1][]="修改默认首页 成功!";
                $BRK_MSG[0]=1;
            }else {
                $BRK_MSG[1][]="修改默认首页 失败! SQL语句错误";
                $BRK_MSG[0]=0;
            }
        }else {
            $BRK_MSG[1][]="修改默认首页 失败! 非法参数";
        }

        foreach ($_POST['cname'] as $key => $value) {
            if(empty($value)) {
                $BRK_MSG[1][]="频道".$key." 为空了,不可以这样";
            }else {
                if(brk_update(
                "channels",
                array("cname"=>$value,"navishow"=>intval($_POST['navishow'][$key]),"status"=>intval($_POST['status'][$key]),"sort"=>intval($_POST['sort'][$key])),
                "WHERE ename='".$key."'")) {
                    $BRK_MSG[1][]="修改 $key 成功!";
                    $BRK_MSG[0]=1;
                }else {
                    $BRK_MSG[1][]="修改 $key 失败! SQL语句错误";
                    $BRK_MSG[0]=0;
                }
            }
            brk_bglog("修改默认首页为".$_POST['thisisindex']);
        }
        $BRK_MSG[2]=0;

        // 更新site.php 缓存文件中的BRK_CHA
        brk_ceche_site(1);
        // 更新con_channels下的缓存文件
        brk_ceche_CHA();

        break;
    default:
        break;
}

?>